package com.hkw.servlet;

import com.hkw.model.ClassRoom;
import com.hkw.service.IClassRoomService;
import com.hkw.service.impl.ClassRoomServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 教室更新请求的Servlet
 */
@WebServlet(name = "UpdateClassRoomServlet",urlPatterns = "/updateClassRoom")
public class UpdateClassRoomServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id = request.getParameter("id");
        String name = request.getParameter("name");
        String grade = request.getParameter("grade");
        String classTeaName = request.getParameter("classTeaName");
        String solgan = request.getParameter("slogan");
        String number = request.getParameter("number");
        ClassRoom classRoom = new ClassRoom(Integer.parseInt(id),name,grade,classTeaName,solgan,Integer.parseInt(number));
        //调用服务类的服务
        IClassRoomService classRoomService = new ClassRoomServiceImpl();
        int update = classRoomService.updateClassRoom(classRoom);
        if(update ==1){
            response.sendRedirect("classRoomList");
        }else{
            response.sendRedirect("classRoomList");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
